from django.utils import timezone
from django.db import models

datetime_format = "%Y/%m/%d %H:%M:%S %Z"


class User(models.Model):
	uid = models.CharField(max_length=36, primary_key=True)
	nickname = models.CharField(max_length=20)
	account = models.CharField(max_length=18, unique=True)
	password = models.CharField(max_length=32)
	createTime = models.DateTimeField(null=True)

	def __str__(self):
		return "{}: {}".format(self.uid[0:5], self.nickname)


class Content(models.Model):
	cid = models.CharField(max_length=36, primary_key=True)
	content = models.TextField()
	user = models.ForeignKey(User, on_delete=models.CASCADE, default=None)
	time = models.DateTimeField()
	read = models.BooleanField()
	device = models.CharField(max_length=50, null=True, blank=True)

	def __str__(self):
		return timezone.localtime(self.time).strftime(datetime_format)


